<%@ page session="false" language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="ko">
<head>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no,target-densitydpi=medium-dpi"/>
	<title>대기</title>
</head>
<body>
<center><img alt="" src="http://placehold.it/200x300.gif&text=waiting"></center>
</body>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.4.3.min.js"></script>
<script type="text/javascript" charset="utf-8" src="${contextPath }/js/lib/jindo.all.js"></script>
<script type="text/javascript" charset="utf-8" src="${contextPath }/js/lib/jindo_component.all.js"></script>
<script type="text/javascript">

var o = new jindo.Timer(); 
var repeatCounter=0;
var repeatCurrentCounter=0;
o.start(function() { 
	var checkUrl = "/gonu/play/api/check.json?chnlNumber=${chnlNumber}";
	var ajax = $Ajax(checkUrl, {
		type : 'xhr',
        method : 'get', 
        async : false,
        onload : function(res) {
        	repeatCurrentCounter--;
            if(!!res){
				var response = res.json();
				var message = response.message;
				if(message == "ok"){
					alert("게임시작");
					o.abort();
					location.href = "/gonu/play/view.gonu";			
				} 			
			} 
        }
    });
	
	// check < 2
	if(repeatCurrentCounter < 2) {
		ajax.request();
		repeatCurrentCounter++;
		repeatCounter++;
	}
	
	return true;
}, 1000);
</script>
</html>
